using UnityEngine;
using System.Collections;

/// \class  gkShootInRhythmShipFire
/// \brief  Handle the fire event
[AddComponentMenu("GK/ShootInRhythm/Ship/gkShootInRhythmShipFire")]
[RequireComponent(typeof(gkEventComponent))]
public class gkShootInRhythmShipFire : MonoBehaviour 
{	
	/// The object to fire
	public GameObject FireObject;
	
	/// The point from which we fire
	public Transform FireFrom;
	
	/// \brief  Called when the component is enabled
	void OnEnable() 
	{
		// Listen the shock event of the owner
		GetComponent<gkEventComponent>().AddEventHandler(gkShootInRhythmFireEvent.StartFire, HandleStartFireEvent);
	}
	
	/// \brief  Called when the component is disabled
	void OnDisable() 
	{	
		// Remove the shock event of the owner
		GetComponent<gkEventComponent>().RemoveEventHandler(gkShootInRhythmFireEvent.StartFire, HandleStartFireEvent);
	}
	
	/// \brief  Handle the event
	void HandleStartFireEvent(Object a_rEvent)
	{
		GameObject FiredObject;
		
		// Create the object
		FiredObject = Instantiate(FireObject) as GameObject;
		
		// Position it
		FiredObject.transform.position = FireFrom.position;
		FiredObject.transform.rotation = FireFrom.rotation;
	}
}
